package com.aurora.app.util;

import org.json.JSONObject;

import com.aurora.base.util.HTTPSRequest;


/**
 * 发送模板消息
 * @author yongjiang.lin
 *
 */
public class SendTemplate {
	private static final String send_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=ACCESS_TOKEN";
	/**
	 * 扫码后，告知支付成功
	 * @param openid 告知用户openid
	 * @param url 点击跳转的地址
	 * @param firstInfo 标题
	 * @param orderMoneySumInfo  订单金额
	 * @param orderProductNameInfo 物品名称
	 * @param RemarkInfo 备注
	 * @param accessToken 
	 * @return
	 */
	public static boolean sendPaySuccess(String openid, String url, String firstInfo,
			String orderMoneySumInfo, String orderProductNameInfo, String RemarkInfo,
			String accessToken) {
		try {
			JSONObject jsonObject = new JSONObject();
			jsonObject.put("touser", openid);
			jsonObject.put("template_id",
					"zKd4MIjKnS9nrd7Gco_gAJ13QWK5La7AqNENOKcD18s");
			jsonObject.put("url", url);
			jsonObject.put("topcolor", "#000");
			JSONObject data = new JSONObject();
			JSONObject first = new JSONObject();
			first.put("value", firstInfo + "\r\n ");
			first.put("color", "#000");
			
			JSONObject orderMoneySum = new JSONObject();
			orderMoneySum.put("value", orderMoneySumInfo);
			orderMoneySum.put("color", "#000");
			
			JSONObject orderProductName = new JSONObject();
			orderProductName.put("value", orderProductNameInfo);
			orderProductName.put("color", "#000");
			
			JSONObject Remark = new JSONObject();
			Remark.put("value", "\r\n" + RemarkInfo);
			Remark.put("color", "#000");

			data.put("first", first);
			data.put("orderMoneySum", orderMoneySum);
			data.put("orderProductName", orderProductName);
			data.put("Remark", Remark);
			jsonObject.put("data", data);

			String requestUrl = send_url.replace("ACCESS_TOKEN", accessToken);
			String resule = HTTPSRequest.httpsRequest(requestUrl, "POST",
					jsonObject.toString());
			System.out.println("resule==" + resule);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}
	
//	public static boolean sendPaySuccess(String openid, String url, String firstInfo,
//			String orderMoneySumInfo, String orderProductNameInfo, String RemarkInfo,
//			String accessToken) {
//		try {
//			JSONObject jsonObject = new JSONObject();
//			jsonObject.put("touser", openid);
//			jsonObject.put("template_id",
//					"zKd4MIjKnS9nrd7Gco_gAJ13QWK5La7AqNENOKcD18s");
//			jsonObject.put("url", url);
//			jsonObject.put("topcolor", "#000");
//			JSONObject data = new JSONObject();
//			JSONObject first = new JSONObject();
//			first.put("value", firstInfo + "\r\n ");
//			first.put("color", "#000");
//			
//			JSONObject orderMoneySum = new JSONObject();
//			orderMoneySum.put("value", orderMoneySumInfo);
//			orderMoneySum.put("color", "#000");
//			
//			JSONObject orderProductName = new JSONObject();
//			orderProductName.put("value", orderProductNameInfo);
//			orderProductName.put("color", "#000");
//			
//			JSONObject Remark = new JSONObject();
//			Remark.put("value", "\r\n" + RemarkInfo);
//			Remark.put("color", "#000");
//
//			data.put("first", first);
//			data.put("orderMoneySum", orderMoneySum);
//			data.put("orderProductName", orderProductName);
//			data.put("Remark", Remark);
//			jsonObject.put("data", data);
//
//			String requestUrl = send_url.replace("ACCESS_TOKEN", accessToken);
//			String resule = HTTPSRequest.httpsRequest(requestUrl, "POST",
//					jsonObject.toString());
//			System.out.println("resule==" + resule);
//		} catch (Exception e) {
//			// TODO: handle exception
//		}
//		return false;
//	}

	
}
